package com.shujia.mllib

import java.io.StringReader

import org.wltea.analyzer.core.IKSegmenter
import org.wltea.analyzer.core.Lexeme

import scala.collection.mutable.ListBuffer

object IK {


  def main(args: Array[String]): Unit = {

    val text = "自古刀扇过背刺"
    val sr = new StringReader(text)
    val ik = new IKSegmenter(sr, true)

    //每次循环取出一个词
    var lex = ik.next
    while (lex != null) {
      println(lex.getLexemeText)
      lex = ik.next
    }

    fit("自古刀扇过背刺")
  }

  def fit(text: String): List[String] = {
    val sr = new StringReader(text)
    val ik = new IKSegmenter(sr, true)

    val lf = new ListBuffer[String]

    var lex = ik.next
    while (lex != null) {
      lf.+=(lex.getLexemeText)
      lex = ik.next
    }

    lf.toList
  }
}
